package com.haoshuang.zhouzhoubang.ui.page.order.upload

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.LogBen
import com.haoshuang.zhouzhoubang.model.bean.OrderBean5
import com.haoshuang.zhouzhoubang.model.bean.OrderDetail2Bean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class UploadInServiceViewModel : BaseViewModel() {
    // 获取订单详情
    val getData = StatefulMutableLiveData<OrderDetail2Bean>()
    fun getData(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderDetail2Bean>("api/master_order/get_master_order_detail", *params,
                onStart = {
                    getData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData.value = StateData.Success(it)
                })
        }
    }

    val getData5 = StatefulMutableLiveData<OrderBean5>()
    fun getData5(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderBean5>("api/master_order/get_master_order_base", *params,
                onStart = {
                    getData5.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData5.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData5.value = StateData.Success(it)
                })
        }
    }

    val getData29 = StatefulMutableLiveData<LogBen>()
    fun getData29(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<LogBen>("api/master_order/getServiceLog", *params,
                onStart = {
                    getData29.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData29.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData29.value = StateData.Success(it)
                })
        }
    }

    val getData012 = StatefulMutableLiveData<Any>()
    fun getData012(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/master_order/do_service", *params,
                onStart = {
                    getData012.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData012.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData012.value = StateData.Success(it)
                })
        }
    }
}